<div class="container" id="ajax_content">
    <?php
        include 'header2.php';
    ?>
    <div class="content">
    	<div class="headcontent">
            <span class="randomtext" style="margin-left:50px">Hi, 
            <?php
                global $session;
                $user_id = $session->get('userid');
                $sql="SELECT fullname FROM user WHERE iduser='$user_id'";
		$result=mysql_query($sql);
		while($res = mysql_fetch_array($result)) {
                    $nama = $res['fullname'];
		}
		echo $nama;
            ?>
            </span>
            <span class="randomtext" style="padding-left:900px">MESSAGES</span>
        	<hr/>
        </div>
        <div class="leftcontent" style="width:350px; margin-left:40px; margin-right:40px">
        <div class="randomtext" style="margin-bottom:20px">Messages List</div>
        <?php
            global $session;
            $user_id = $session->get('userid');
            $query = "SELECT * FROM message WHERE id_sender='$user_id'";
            $result = mysql_query($query);
            $i = 0;
            while ($res = mysql_fetch_array($result)) {
                $id_msg = $res['idmsg'];
                
                echo '<div class="right1" style="border-style: groove"><a href="'.BASE_PATH.'mdetail/index/'.$id_msg.'" ><div value="'.$id_msg.'">Message '.++$i.'</div></a><div>Subject : '.$res['topik'].'</div></div>';
            }

            $query2 = "SELECT * FROM msg_receiver WHERE id_receiver='$user_id'";
            $result2 = mysql_query($query2);
            
            while ($res2 = mysql_fetch_array($result2)) {
                $query3 = "SELECT * FROM message WHERE idmsg='$res2[idmsg]'";
                $result3 = mysql_query($query3);
                $res3 = mysql_fetch_array($result3);
                $id_msg = $res2['idmsg'];
                echo '<div class="right1" style="border-style: groove"><a href="'.BASE_PATH.'mdetail/index/'.$id_msg.'" ><div value="'.$id_msg.'">Message '.++$i.'</div></a><div>Subject : '.$res3['topik'].'</div></div>';
            }
        ?>
            <!--
            <div class="right1" style="border-style: groove">
            	<div>Pesan 1</div>
                <div>Subject</div>
                <div>Sender</div>
                <div>Receiver</div>
            </div>
            <div class="right1" style="border-style: groove">
            	<div>Pesan 2</div>
                <div>Subject</div>
                <div>Sender</div>
                <div>Receiver</div>
            </div>-->
        </div>
        <div class="leftcontent" style="width:850px" style="margin-left:50px; margin-right:50px">
            <div class="randomtext">Create New Message</div>
            <div style="margin-left:90px">
                <form action="<?php echo BASE_PATH . "message/sendmsg" ?>" method="post">
                    <div class="items">
                        <label style="text-align:left">To :</label><br/>
                        <select name="dst">
                            <?php
                                global $session;
                                $user_id = $session->get('userid');
                                $query = "SELECT * FROM follow_user WHERE iduser='$user_id'";
                                $result = mysql_query($query);
                                while ($res=mysql_fetch_array($result)) {
                                    $query2 = "SELECT * FROM user WHERE iduser='$res[idfollowed]'";
                                    $result2 = mysql_query($query2);
                                    $res2 = mysql_fetch_array($result2);
                                    echo '<option value="'.$res2['iduser'].'">'.$res2['fullname'].'</option>';
                                }

                                $query = "SELECT * FROM follow_user WHERE idfollowed='$user_id'";
                                $result = mysql_query($query);
                                while ($res=mysql_fetch_array($result)) {
                                    $query2 = "SELECT * FROM user WHERE iduser='$res[iduser]'";
                                    $result2 = mysql_query($query2);
                                    $res2 = mysql_fetch_array($result2);
                                    echo '<option value="'.$res2['iduser'].'">'.$res2['fullname'].'</option>';
                                }
                            ?>
                        </select>
                    </div>
                    <div class="items">
                        <label style="text-align:left">Subject :</label><br/>
                        <input type="text" name="subject" style="width:600px" />
                    </div>
                    <div class="items">
                        <label style="text-align:left">Message :</label><br/>
                        <textarea name="msg" rows="10" cols="73"></textarea>
                    </div>
                    <div class="items">
                        <button type="submit">Send</button>
                    </div>
                </form>
            </div>
        </div>
        <div class="clearboth"></div>
    </div>
    <div class="footer"></div>
</div>

